package jomm.utils;

import java.util.Properties;
import java.util.List;

/**
 * @author Jorge Machado
 * @date 29/Dez/2007
 * @time 1:47:22
 */
public abstract class ConfigProperties {

    private Properties props = null;

    public abstract String getPath();

    /**
     * Load properties
     * @return properties
     */
    public Properties getProperties()
    {
        if(props == null)
        {
            props = new Properties();
            try
            {
                props.load(ConfigProperties.class.getResourceAsStream(getPath()));
            }
            catch (Exception ex)
            {
                throw new ExceptionInInitializerError(ex);
            }
        }
        return props;
    }


    public Properties getProps()
    {
        return props;
    }

    /**
     * Get property and convert it to float
     *
     * @param property to get and convert
     * @return float value
     */
    public float getFloat(String property)
    {
        return PropertiesUtils.getFloatProperty(property, getProperties());
    }

    /**
     * Get property and convert it to float
     *
     * @param property to get and convert
     * @return boolean value
     */
    public boolean getBoolean(String property)
    {
        return PropertiesUtils.getBooleanProperty(property, getProperties());
    }



    /**
     * Get property and convert it to short
     *
     * @param property to get and convert
     * @return float value
     */
    public short getShort(String property)
    {

        return PropertiesUtils.getShortProperty(property, getProperties());
    }

    /**
     * Get property and convert it to int
     *
     * @param property to get and convert
     * @return int value
     */
    public int getInt(String property)
    {

        return PropertiesUtils.getIntProperty(property, getProperties());
    }


    /**
     *
     * @param property to load
     * @return property value
     */
    public String getProp(String property)
    {
        return getProperties().getProperty(property);
    }

    /**
     * @param propertyPrefix to load
     * @return a list of all property names hat starts with the given
     * prefix
     */
    public List<String> getListProps(String propertyPrefix)
    {
        return PropertiesUtils.getListProperties(getProperties(),propertyPrefix);
    }

    /**
     * @param propertyPrefix to load
     * @return a list of all property names hat starts with the given
     * prefix
     */
    public List<String> getListVals(String propertyPrefix)
    {
        return PropertiesUtils.getListValuesOrderedByPropertyName(getProperties(),propertyPrefix);
    }

    
    /**
     * @param propertyPrefix to load
     * @return a list of all property names hat starts with the given
     * prefix
     */
    public List<String> getListValsOrderedByValue(String propertyPrefix)
    {
        return PropertiesUtils.getListValuesOrderedByValue(getProperties(),propertyPrefix);
    }

    
    /**
     * @param propertyPrefix to load
     * @return a list of all property names hat starts with the given
     * prefix
     */
    public List<String> getListValsOrderedByPropertyName(String propertyPrefix)
    {
        return PropertiesUtils.getListValuesOrderedByPropertyName(getProperties(),propertyPrefix);
    }
}
